package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {
    @Autowired
    private RegionMapper regionMapper;

    public List<Region> selectByParentId(Long parentId) {
        return regionMapper.selectByParentId(parentId);
    }

    public void saveOrUpdate(Region region) {
        if (region.getId() != null) {
            regionMapper.updateByPrimaryKey(region);
        }else {
            region.setState(Region.STATE_COMMON);
            regionMapper.insert(region);
        }
    }

    public void updateStateById(Long id,Integer state) {
        if (id != null) {
            regionMapper.updateStateById(id,state);
        }
    }

    public List<Region> listAll() {
        return regionMapper.selectAll();
    }

    @Override
    public List<Region> selectByState(Integer state) {
        return regionMapper.selectByState(state);
    }
}
